package com.wipz.eoa.iphone.news;

import java.util.HashMap;
import java.util.Map;

import com.toft.widgets.workflow.model.CompleteTaskResult;
import com.toft.widgets.workflow.utils.ConstantUtil;
import com.wipz.eoa.iphone.businessProcess.BusinessCoreServices;
import com.wipz.eoa.iphone.util.DataUtil;

public class NewsViewServiceImpl extends BusinessCoreServices implements
		INewsViewService {

	@Override
	public void insertReadStatus(Map map) {
		getBaseDao().insert("news.insertreadstatus", map);
	}

	@Override
	public Object detail(Map map) {
		Map m = (Map) getBaseDao().queryOne("news.queryById",map);
		String contents = (String) m.get("CONTENTS");
		//ȡ��������ͼƬ·��
		 String img = DataUtil.getImgStr(contents);
		 m.put("IMG", img);
		 //����ͼƬ��Ϣ
		 contents = DataUtil.filterImg(contents);
		 m.put("CONTENTS", contents);
		 return m;
	}

	@Override
	public Map bxSubmit(Map param) {
		String COMMITERCODE = (String) param.get("COMMITERCODE");
		//任务唯一标识taskId
		String taskId = (String) param.get("taskId");
		//处理意见
		String commentContent = (String) param.get("comment");
		//流向
		String transition = (String) param.get("name");
		//处理类型
		String typeaccept = (String)param.get("pass");
		
		String uuitId = (String) param.get("UuitId");
		
		String id = (String) param.get("ID");
		
		boolean pass = typeaccept =="true" ? true:false;
		Map variable = new HashMap();
		variable.put(ConstantUtil.TASK_COMMNET_TYPE, ConstantUtil.APPROVE_OPERATION_PASS.equals(typeaccept) ? ConstantUtil.TASK_COMMNET_TYPE_ACCEPT : ConstantUtil.TASK_COMMNET_TYPE_REFUSE); // 意见类型
		variable.put(ConstantUtil.TASK_COMMENT_CONTENT, commentContent); // 意见内容
		CompleteTaskResult result = this.complete(COMMITERCODE, taskId, transition, variable, pass,uuitId);
		if(result == null ) {
			return null;
		}
		String process_status = "1";
		if(result.isEnded()){
			process_status = "2";
		}else if(result.isBack()){
			process_status = "4";
		}
		String nextOne = result.getNextOperators();
		Map map = new HashMap();
		map.put("ID",id);
		map.put("PROCESS_STATUS", process_status);
		super.update("news.changeprocessstatus", map);
		if("".equals(nextOne)||result.isEnded())
			nextOne = "审批结束";
		map.put("NEXTOPERATOR", nextOne);
		super.update("news.getnext",map);
		//this.getContext().addAttribute("result", result);
		Map resultMap = new HashMap();
		resultMap.put("back", result.isBack()+"");
		resultMap.put("ended", result.isEnded()+"");
		resultMap.put("nextOperators", result.getNextOperators());
		return resultMap;
	}
	
	public String submit(String businessid,String uuid,String billCode,String COMMITERCODE,String agencyId,String remark) {
		return super.submit(businessid, uuid, billCode, COMMITERCODE, agencyId, remark);
	}

}
	

